<?php
/*
 * Created on Apr 26, 2012
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

$qid = $_GET['questionid'];
 
$conn = mysql_connect('localhost','root','vertrigo') or die('can not connect to server');
mysql_select_db('iblog',$conn);
if (isset($_POST['ok'])){
	$id = $_POST['answer'];
	$sql = "update answer set acount = acount + 1 where aid = '". $id ."'";
	mysql_query($sql);
	mysql_close();
	header("location: result.php?questionid=$qid");	
	exit();
}
$sql1 = "select * from question where qid='". $qid ."'";
$query1 = mysql_query($sql1);
if (mysql_num_rows($query1)){
	$row1 = mysql_fetch_array($query1); 
?>

<html>
	<head>
		<title>Poll</title>
	</head>
	<body>
		<form action="poll.php?questionid=<?php echo $qid; ?>" method="post">
			<?php 
				echo '<b>'. $row1['qtitle'] .'</b><br/>'; 
				$sql2 = "select * from answer where qid='".$qid."' order by aid";
				$query2 = mysql_query($sql2);
				while ($row2 = mysql_fetch_array($query2)){
					echo '<input type="radio" name="answer" value="'.$row2['aid'] .'">'. $row2['atitle'] .'<br/>';
				}			
			?>							
			<input type="submit" name="ok" value="Poll"/>
			<a href="result.php?questionid=<?php echo $qid; ?>">View Result</a>
		</form>
	</body>
</html>

<?php
}
?>